<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of terms_model
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Admin_photos_model extends CI_Model {

    //put your code here

    function __construct() {
        parent::__construct();
        log_message('debug', 'Model Initialized');
    }
//--Get Term results -- Subha (28/08/2012) ---    //
/*
function get_photos($featured = false, $status = 1, $no = NULL, $offset = NULL) {
        if (!$this->db->table_exists('photos')) {
            return FALSE;
        }
        $sql = "select * from photos where status=$status order by id";
        $query = $this->db->query($sql);
        $result = $query->result();
        return $result;
    }
  */  
    
    
   /* function get_photos($featured = false, $status = 1, $no = NULL, $offset = NULL){
    	$sql = "Select * from photos where status=$status order by id desc";
    	$query = $this->db->query($sql);
    	$result = $query->result();
    	return $result;
    }
 */
    
    function get_photos($featured=false, $status=1,$num=NULL, $offset=NULL) {
    	$subcond = "where status=$status";
    	$limit = "";
    	if (isset($num) && isset($offset))
    		$limit = " order by (id) desc limit $offset, $num";
    	$sql = "select * from photos " . $subcond . $limit;
    	$query = $this->db->query($sql);
    	$result = $query->result();
    	return $result;
    }
    
    function get_inactive_photos($featured=false, $status=51,$num=NULL, $offset=NULL) {
    	$subcond = "where status=$status";
    	$limit = "";
    	if (isset($num) && isset($offset))
    		$limit = " order by (id) desc limit $offset, $num";
    	$sql = "select * from photos " . $subcond . $limit;
    	$query = $this->db->query($sql);
    	$result = $query->result();
    	return $result;
    }
    
    function change_status($id, $status) {
    	if ($status == 1) {
    		$sql = "update photos set status=51 where id=$id";
    	}
    	if ($status == 51) {
    		$sql = "update photos set status=1 where id=$id";
    	}
    	$this->db->query($sql);
    }
    
    function delete_photo($id,$image_file) {
    	if($id && $image_file){
    		$sql="delete from photos where id = $id";
    		$this->db->query($sql);
    		//--Delete Image File --//
    
    		$f = BASEPATH.'../assets/images/data/photos/'.$image_file;
    		//$f = base_url()."assets/images/data/advertisement/".$image_file;
    
    		unlink($f);
    	}
    }
}
 
 

?>